/*
 * @Author: your name
 * @Date: 2021-10-09 11:24:40
 * @LastEditTime: 2021-10-09 13:45:00
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \test_algorithm\threadsafe_vector.hpp
 */
#include <mutex>
#include <vector>
#include <stdint.h>

template<typename TYP>
class ThreadSafeVector  {
public:
	typedef typename std::vector<TYP>::iterator iterator;
	typedef typename std::vector<TYP>::const_iterator const_iterator;
	ThreadSafeVector(size_type n){
		this->m_data = new vector<TYP>(n);
	}

    const Val& operator [](uin32_t index) 
	{
        std::unique_lock<std::mutex> lck(m_mutex);
		return *m_data[index];
	}
	const Val& at(uin32_t index) 
	{
        std::unique_lock<std::mutex> lck(m_mutex);
		return m_data->at(index);
	}
	iterator Insert(TYP dat,iterator pos){
        std::unique_lock<std::mutex> lck(m_mutex);
		*m_data.insert(pos,dat);
	}
private:
    std::vector<TYP> *m_data;
    std::mutex m_mutex;
}

